﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using HangerSupport.Properties;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace HangerSupport
{
	public partial class DlgHsSeiComRev : System.Windows.Forms.Form
	{
		public DlgHsSeiComRev()
		{
			this.InitializeComponent();
			YJKProcessTools hyprocessTools = new YJKProcessTools();
			hyprocessTools.ShowInTaskbarChange(this);
			base.Icon = YArchitech.LIB.Resources.YArchitech;
			this.userSetting = new UserSetting();
		}

		public AdjustedType AdjustType
		{
			get
			{
				return this.adjustType;
			}
			set
			{
				this.adjustType = value;
			}
		}

		public bool CmdEsc
		{
			get
			{
				return this.cmdEsc;
			}
			set
			{
				this.cmdEsc = value;
			}
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void rdoRotate_CheckedChanged(object sender, EventArgs e)
		{
			RadioButton radioButton = sender as RadioButton;
			bool flag = radioButton != null;
			if (flag)
			{
				string name = radioButton.Name;
				if (!(name == "rdoRotate"))
				{
					if (!(name == "rdoAlgPipeMirr"))
					{
						if (name == "rdoSameSideMirr")
						{
							this.adjustType = AdjustedType.SameSideMirror;
						}
					}
					else
					{
						this.adjustType = AdjustedType.AlongPipeMirror;
					}
				}
				else
				{
					this.adjustType = AdjustedType.Rotate;
				}
			}
			bool flag2 = this.cmdEsc;
			if (flag2)
			{
			}
		}

		private void DlgHsSeiComRev_Load(object sender, EventArgs e)
		{
			this.picPreview.Image = HangerSupport.Properties.Resources.rotateHanger;
			base.KeyPreview = true;
			this.Initializate();
			this.cmdEsc = false;
		}

		private void DlgHsSeiComRev_KeyPress(object sender, KeyPressEventArgs e)
		{
			bool flag = e.KeyChar == '\u001b';
			if (flag)
			{
				base.Close();
			}
		}

		private void DlgHsSeiComRev_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.WriteData();
			this.MimicEsc();
			this.cmdEsc = true;
		}

		private void MimicEsc()
		{
			byte bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			int wMsg = 7;
			DlgHsSeiComRev.SendMessage(cmdReverSeismicComponent.wndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			DlgHsSeiComRev.keybd_event(bVk, 0, dwFlags, 0);
			DlgHsSeiComRev.keybd_event(bVk, 0, dwFlags2, 0);
			this.cmdEsc = false;
		}

		private void Initializate()
		{
			string value = this.userSetting.GetValue("SeismicComponentsRotate", "RotateType");
			string a = value;
			if (!(a == "1"))
			{
				if (!(a == "2"))
				{
					if (!(a == "3"))
					{
						this.rdoRotate.Checked = true;
					}
					else
					{
						this.rdoSameSideMirr.Checked = true;
					}
				}
				else
				{
					this.rdoAlgPipeMirr.Checked = true;
				}
			}
			else
			{
				this.rdoRotate.Checked = true;
			}
		}

		private void WriteData()
		{
			string text = "";
			bool @checked = this.rdoRotate.Checked;
			if (@checked)
			{
				text = "1";
			}
			else
			{
				bool checked2 = this.rdoAlgPipeMirr.Checked;
				if (checked2)
				{
					text = "2";
				}
				else
				{
					bool checked3 = this.rdoSameSideMirr.Checked;
					if (checked3)
					{
						text = "3";
					}
				}
			}
			this.userSetting.WriteValue("SeismicComponentsRotate", "RotateType", text);
		}

		private AdjustedType adjustType;

		private bool cmdEsc = false;

		private UserSetting userSetting = null;
	}
}
